local thbattle__cheng_feixiang = fk.CreateSkill {

  name = "thbattle__cheng_feixiang",

  tags = {},

}



thbattle__cheng_feixiang:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(thbattle__cheng_feixiang.name) and player.phase == Player.Play and
        player:usedSkillTimes(thbattle__cheng_feixiang.name, Player.HistoryPhase) == 0
        and data.card and data.card.multiple_targets ~= true and #table.filter(player.room.alive_players, function(p)
          return player:canUseTo(data.card, p)
        end) > 1 and
        (data.card.trueName == "slash" or (data.card:isCommonTrick() and data.card.trueName ~= "collateral"))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, thbattle__cheng_feixiang.name) then
      local targets = {}
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not table.contains(data.tos, p) and not player:isProhibited(p, data.card) then
          if player:inMyAttackRange(p) and data.card.trueName == "slash" then
            table.insertIfNeed(targets, p.id)
          elseif data.card:isCommonTrick() and data.card.trueName ~= "collateral" then
            table.insertIfNeed(targets, p.id)
          end
        end
      end
      if #targets > 0 then
        local tos = room:askForChoosePlayers(player, targets, 1, 1, "#thbattle__cheng_feixiang-choose",
          thbattle__cheng_feixiang
          .name, true)
        if #tos > 0 then
          event:setCostData(self, tos[1])
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    data:addTarget(player.room:getPlayerById(event:getCostData(self)))
  end
})

return thbattle__cheng_feixiang
